package mysgoog.pattern.StartGame;

import java.io.*;
import java.util.*;
/**
* @author Fu, Zhongyang
*/
public class StartGamePatternLoader
{

    public final static int MaxPatternStep = 100;
    private static Map<String, Integer> patternMap = null;

    public static void load(Map<String, Integer> map)
    {
        patternMap = map;
        read("pattern\\gogo.pattern");
        read("pattern\\hoshi_keima.pattern");
        read("pattern\\hoshi_other.pattern");
        read("pattern\\komoku.pattern");
        read("pattern\\KJD.pattern");
    }

    public static void read(String filename)
    {
        BufferedReader reader = null;
        try
        {
            File file = new File(filename);
            reader = new BufferedReader(new FileReader(file));
            String text = null;
            while ((text = reader.readLine()) != null)
            {
                parse(text);
            }
        } catch (FileNotFoundException e)
        {
            e.printStackTrace();
        } catch (IOException e)
        {
            e.printStackTrace();
        } finally
        {
            try
            {
                if (reader != null)
                {
                    reader.close();
                }
            } catch (IOException e)
            {
                e.printStackTrace();
            }
        }
    }

    public static void parse(String pattern)
    {
        String[] token = pattern.split(" ");
        if (Integer.parseInt(token[0]) > MaxPatternStep)
            return;
        // System.out.println(pattern);
        if (patternMap.get(token[1]) == null)
            patternMap.put(token[1], Integer.parseInt(token[2]));
    }
}
